<?php

class FileField extends Object
{
    var $Type = 'FileField';    
    
    var $_Name;
    var $_Title;
    var $_Description;
    var $_Value;
    var $_Mode;

    function __construct(&$form, $name, $title, $description = '', $required = false)
    {
        // Field Properties
        $this->_Name        = $name;
        $this->_Title       = $title;
        $this->_Description = $description;
        $this->_Mode        = $required?'required':'normal';
        
        // Adjust the form enctype
        $form->SetEncType('multipart/form-data');
    }
       
    function Validate()
    {
        if ($this->_Mode == 'required')
        {
            if (!isset($_FILES[$this->_Name]) || ($_FILES[$this->_Name]['error'] != UPLOAD_ERR_OK))
            {
                $this->_Mode = 'error';
                return false;
            }
            else 
                return true;
        }
        else
            return true;
    }

    function ToArray()
    {
        return array('type'        => 'FileField',
                     'name'        => $this->_Name,
                     'title'       => $this->_Title,
                     'description' => $this->_Description,
                     'mode'        => $this->_Mode);
    }
}

?>